from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-07 14:15:20.282780
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 07, Oct, 2022
Time: 14:15:27
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.6297
Nobs: 802.000 HQIC: -50.9537
Log likelihood: 10361.5 FPE: 6.07252e-23
AIC: -51.1557 Det(Omega_mle): 5.43168e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.297572 0.052860 5.629 0.000
L1.Burgenland 0.109043 0.035542 3.068 0.002
L1.Kärnten -0.106407 0.018921 -5.624 0.000
L1.Niederösterreich 0.210080 0.074331 2.826 0.005
L1.Oberösterreich 0.100697 0.071315 1.412 0.158
L1.Salzburg 0.251781 0.037894 6.644 0.000
L1.Steiermark 0.038229 0.049581 0.771 0.441
L1.Tirol 0.106281 0.040200 2.644 0.008
L1.Vorarlberg -0.059367 0.034559 -1.718 0.086
L1.Wien 0.056594 0.063735 0.888 0.375
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.064425 0.109459 0.589 0.556
L1.Burgenland -0.033605 0.073597 -0.457 0.648
L1.Kärnten 0.047845 0.039180 1.221 0.222
L1.Niederösterreich -0.172330 0.153919 -1.120 0.263
L1.Oberösterreich 0.385307 0.147674 2.609 0.009
L1.Salzburg 0.287286 0.078468 3.661 0.000
L1.Steiermark 0.106205 0.102669 1.034 0.301
L1.Tirol 0.313411 0.083244 3.765 0.000
L1.Vorarlberg 0.025162 0.071561 0.352 0.725
L1.Wien -0.017065 0.131977 -0.129 0.897
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189894 0.027137 6.998 0.000
L1.Burgenland 0.090189 0.018246 4.943 0.000
L1.Kärnten -0.008437 0.009713 -0.869 0.385
L1.Niederösterreich 0.264655 0.038159 6.936 0.000
L1.Oberösterreich 0.126565 0.036611 3.457 0.001
L1.Salzburg 0.047455 0.019453 2.439 0.015
L1.Steiermark 0.016835 0.025453 0.661 0.508
L1.Tirol 0.094273 0.020638 4.568 0.000
L1.Vorarlberg 0.059271 0.017741 3.341 0.001
L1.Wien 0.120363 0.032719 3.679 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109772 0.027812 3.947 0.000
L1.Burgenland 0.044428 0.018700 2.376 0.018
L1.Kärnten -0.016086 0.009955 -1.616 0.106
L1.Niederösterreich 0.193263 0.039109 4.942 0.000
L1.Oberösterreich 0.293916 0.037522 7.833 0.000
L1.Salzburg 0.114985 0.019938 5.767 0.000
L1.Steiermark 0.099874 0.026087 3.829 0.000
L1.Tirol 0.116255 0.021151 5.496 0.000
L1.Vorarlberg 0.070595 0.018183 3.883 0.000
L1.Wien -0.027354 0.033534 -0.816 0.415
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.128697 0.050443 2.551 0.011
L1.Burgenland -0.051223 0.033917 -1.510 0.131
L1.Kärnten -0.040274 0.018056 -2.231 0.026
L1.Niederösterreich 0.170603 0.070933 2.405 0.016
L1.Oberösterreich 0.137603 0.068054 2.022 0.043
L1.Salzburg 0.285651 0.036161 7.899 0.000
L1.Steiermark 0.034209 0.047314 0.723 0.470
L1.Tirol 0.164186 0.038363 4.280 0.000
L1.Vorarlberg 0.103709 0.032979 3.145 0.002
L1.Wien 0.069107 0.060821 1.136 0.256
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060231 0.039988 1.506 0.132
L1.Burgenland 0.038464 0.026887 1.431 0.153
L1.Kärnten 0.050660 0.014313 3.539 0.000
L1.Niederösterreich 0.225832 0.056231 4.016 0.000
L1.Oberösterreich 0.282321 0.053949 5.233 0.000
L1.Salzburg 0.050931 0.028666 1.777 0.076
L1.Steiermark -0.007095 0.037508 -0.189 0.850
L1.Tirol 0.149815 0.030411 4.926 0.000
L1.Vorarlberg 0.070904 0.026143 2.712 0.007
L1.Wien 0.078876 0.048215 1.636 0.102
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.178701 0.047794 3.739 0.000
L1.Burgenland -0.005798 0.032136 -0.180 0.857
L1.Kärnten -0.061072 0.017108 -3.570 0.000
L1.Niederösterreich -0.083091 0.067208 -1.236 0.216
L1.Oberösterreich 0.192609 0.064481 2.987 0.003
L1.Salzburg 0.056653 0.034262 1.654 0.098
L1.Steiermark 0.230786 0.044830 5.148 0.000
L1.Tirol 0.493626 0.036348 13.580 0.000
L1.Vorarlberg 0.049285 0.031247 1.577 0.115
L1.Wien -0.049332 0.057627 -0.856 0.392
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161575 0.054878 2.944 0.003
L1.Burgenland -0.011053 0.036898 -0.300 0.765
L1.Kärnten 0.065979 0.019643 3.359 0.001
L1.Niederösterreich 0.201177 0.077168 2.607 0.009
L1.Oberösterreich -0.061897 0.074037 -0.836 0.403
L1.Salzburg 0.215833 0.039340 5.486 0.000
L1.Steiermark 0.113867 0.051474 2.212 0.027
L1.Tirol 0.076781 0.041735 1.840 0.066
L1.Vorarlberg 0.124388 0.035878 3.467 0.001
L1.Wien 0.115523 0.066168 1.746 0.081
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.354046 0.031926 11.089 0.000
L1.Burgenland 0.006147 0.021466 0.286 0.775
L1.Kärnten -0.023539 0.011428 -2.060 0.039
L1.Niederösterreich 0.224110 0.044894 4.992 0.000
L1.Oberösterreich 0.175448 0.043073 4.073 0.000
L1.Salzburg 0.046962 0.022887 2.052 0.040
L1.Steiermark -0.017247 0.029946 -0.576 0.565
L1.Tirol 0.108549 0.024280 4.471 0.000
L1.Vorarlberg 0.073433 0.020873 3.518 0.000
L1.Wien 0.053432 0.038494 1.388 0.165
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041112 0.152615 0.190498 0.157196 0.125073 0.113753 0.065801 0.226741
Kärnten 0.041112 1.000000 -0.002532 0.129732 0.041459 0.096093 0.429695 -0.053122 0.101368
Niederösterreich 0.152615 -0.002532 1.000000 0.337076 0.155166 0.300579 0.110884 0.183783 0.327394
Oberösterreich 0.190498 0.129732 0.337076 1.000000 0.232506 0.332850 0.172506 0.172274 0.263192
Salzburg 0.157196 0.041459 0.155166 0.232506 1.000000 0.146792 0.127038 0.148966 0.135273
Steiermark 0.125073 0.096093 0.300579 0.332850 0.146792 1.000000 0.153517 0.141114 0.079826
Tirol 0.113753 0.429695 0.110884 0.172506 0.127038 0.153517 1.000000 0.114782 0.154853
Vorarlberg 0.065801 -0.053122 0.183783 0.172274 0.148966 0.141114 0.114782 1.000000 0.007091
Wien 0.226741 0.101368 0.327394 0.263192 0.135273 0.079826 0.154853 0.007091 1.000000